﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PMS.BLL;
using PMS.Entity;
using PMS.Resources;
using PMS.Win;
using PMS.Utils;
using CrystalDecisions.CrystalReports.Engine;
using PMS.Report;
using CrystalDecisions.Shared;

namespace PMS.ReportViewer
{
    public partial class DoanhThuCuaSanPhamViewer : BaseForm
    {
        public DoanhThuCuaSanPhamViewer(string masanpham, DateTime? tungay, DateTime? denngay)
        {
            InitializeComponent();
            ReportBO rp = new ReportBO();
            ReportClass r = new DanhThuCuaSanPham();
            DataSet ds = rp.BaoCaoDoanhThuCuaSanPham(masanpham,tungay,denngay);
            r.SetDataSource(ds);
            crystalReportViewer1.ReportSource = r;
            crystalReportViewer1.ParameterFieldInfo.Add(CreateParameter("TuNgay", (tungay==null)? "":((DateTime)tungay).ToShortDateString()));
            crystalReportViewer1.ParameterFieldInfo.Add(CreateParameter("DenNgay", (denngay == null) ? "" : ((DateTime)denngay).ToShortDateString()));
        
        }
        private ParameterField CreateParameter(string name, object value)
        {
            // create a new parameter with the same name as the one you used in your report designer.
            // Setup the parameter field and value for the report
            ParameterDiscreteValue pVal = new ParameterDiscreteValue();
            pVal.Value = value; // Set the parameter value
            ParameterField pField = new ParameterField(); //Create a new parameter field to hold the value.
            pField.Name = name; // Use the same parameter field name that you used in the report design.
            pField.CurrentValues.Add(pVal); // Add the value to the field.
            pField.HasCurrentValue = true; // This tells the parameter not to prompt because it already has a value.

            return pField;
        }
    }
}
